import React, { Component } from 'react'
import store from '../../redux/store';
import {jiaAction, jianAction, asyncJiaAction} from '../../redux/actions/ZanActions'
import {addAction, minusAction} from '../../redux/actions/CangActions';

export default class Zan extends Component {
    render() {
        return (
            <div className="container">
                <h2>{store.getState().zan}</h2>
                <hr />
                <button onClick={this.jia}>增加</button>
                <button onClick={this.jian}>减小</button>
                <button onClick={this.asyncJia}>1秒后状态值加1</button>
                <br />
                <h2>{store.getState().cang}</h2>
                <hr />
                <button onClick={this.add}>增加</button>
                <button onClick={this.minus}>减小</button>
            </div>
        )
    }
    add = () => {
        store.dispatch(addAction(10));
    }

    minus = () => {
        store.dispatch(minusAction(4));
    }

    //增加
    jia = () => {
        //增加数值
        store.dispatch(jiaAction(1));
    }
    //减少
    jian = () => {
        //减少数值
        store.dispatch(jianAction(1));
    }

    //异步增加
    asyncJia = () => {
        store.dispatch(asyncJiaAction(1));
        // setTimeout(() => {
        //     store.dispatch(jiaAction(1));
        // }, 1000);
    }

   
}
